# sparecap_bottom.mod    
# by Yu Liu, 01/22/2006.
# Arc-flow model for spare capacity allocaiton at bottom layer

##already defined in sparecap.mod
set FAILSL := 1..MaxEdge;
param FL {FAILSL, EDGES} binary default 0;
# need to be declared somewhere
# for edge, node, or arbitrary failure
param UL {FLOWSL, FAILSL} binary default 0;
param TL {FLOWSL, EDGES} binary default 0;
# can be calculate from F and P

var Qb {FLOWSL, EDGES} binary default 0;
var Gb {EDGES, FAILSL} default 0;

var sl {EDGES} default 0;
minimize sl_cost: (sum {(i1,i2) in EDGES} cl[i1,i2]*sl[i1,i2])/2 ;

s.t. cap_aggrS_b {(i1,i2) in EDGES, k in FAILSL}:
  sl[i1,i2] >= Gb[i1,i2,k];
# s >= G  or s = max G

s.t. spm_comp_b {(i1,i2) in EDGES, k in FAILSL}:
  Gb[i1,i2,k] = sum{(r1,r2) in FLOWSL} 
     ML[r1,r2] * (Qb[r1,r2,i1,i2] * UL[r1,r2,k]);
# G = Q^T M U

s.t. fail_disj_b {(r1,r2) in FLOWSL,(i1,i2) in EDGES}:
  TL[r1,r2,i1,i2] + Qb[r1,r2,i1,i2] <= 1;
# T + Q <= 1

s.t. mass_baS_b {(r1,r2) in FLOWSL, n1 in VERTS}:
  sum {(i1,i2) in EDGES} Qb[r1,r2,i1,i2]*BL[n1,i1,i2]=DL[r1,r2,n1];
# Q B^T = D

s.t. backup_sym_b {(r1,r2) in FLOWSL, (i1,i2) in EDGES:i1<i2}:
  Qb[r1,r2,i1,i2] = Qb[r2,r1,i2,i1];
# Q is symatric for symetric flows

problem find_spare_b:
 sl_cost, cap_aggrS_b, spm_comp_b, fail_disj_b, mass_baS_b, backup_sym_b, Qb, Gb, sl;

